import {getAccount, postAccount, putAccount} from '@/base/api/AccountApi';
import {Account} from '@/base/model/Account';
import {getBanners, postBanner,putbanner} from "@/base/api/BannersApi";
import {Page} from "@/base/Page";
import {Company} from "@/base/model/Company";
import {getAgentList} from "@/base/api/AgentApi";
import {deepAssign} from "@/base/util/Objects";
import {getCompanyList} from '@/base/api/CompanyApi';
import {editBenefits, getBenefits} from "@/base/api/BenefitApi";


export class FormBloc {
  model: any = {
    bannerId:0,
    benefitname: '',
    description:'',
    benefitIcon:'',
  };
  loading = false;
  fileList: Array<any> = []
  num: number = 0;

  // sortId: number = 0;
  // modelId: number = 0;
  isDetail = false;

  hasFormInfo = false;

  load(benefitId: number) {
    return getBenefits(benefitId)
      .then((res) => {
        let dataItem = res.data;
        console.log(res);
        this.model.benefitname = dataItem.benefitname;
        this.model.description = dataItem.description;
        this.model.benefitIcon = dataItem.benefitIcon;
        return res;
      }).finally(() => {
        this.hasFormInfo = true;
      })
  }

  save(model:any) {
    this.loading = true;
    return editBenefits({
      benefitId: model.benefitId,
      benefitname: model.benefitname,
      description: model.description,
      benefitIcon: model.benefitIcon,
    }).then((res) => {
      return res;
    }).finally(() => {
      this.loading = false;
    });
  }
}
